// 常量 更多是用大写来代替!!!

// 首页轮播图
const SWIPERDATA_URL = '/home/swiperdata'

// 首页导航
const CATITEMS_URL = '/home/catitems'

// 首页楼层
const FLOORDATA_URL = '/home/floordata'

// 分类
const CATEGORIES_URL = '/categories'

// 商品列表
const GOODS_SEARCH_URL = '/goods/search'

// 商品详情
const GOODS_DETAIL_URL = '/goods/detail'

// 🚩 特别重要：获取用户token
const USERS_WXLOGIN = '/users/wxlogin'

const MY_ORDERS_CREATE = '/my/orders/create'

const MY_ORDERS_REQ_UNIFIEDORDER = '/my/orders/req_unifiedorder'

const MY_ORDERS_CHKORDER = '/my/orders/chkOrder'

const MY_ORDERS_ALL = '/my/orders/all'

// 用到的接口的地址 不用写完整的 因为我们在之前已经配置好 公共的url

// 此处第二个参数vm，就是我们在页面使用的this，你可以通过vm获取vuex等操作，更多内容详见uView对拦截器的介绍部分：

const install = (Vue, vm) => {
  // 此处没有使用传入的params参数

  // 首页
  const getSwiperdata = (params = {}) => vm.$u.get(SWIPERDATA_URL, params)
  const getCatitems = (params = {}) => vm.$u.get(CATITEMS_URL, params)
  const getFloordata = (params = {}) => vm.$u.get(FLOORDATA_URL, params)

  // 分类页面
  const getCategories = (params = {}) => vm.$u.get(CATEGORIES_URL, params)

  // 商品列表
  const getGoods = (params = {}) => vm.$u.get(GOODS_SEARCH_URL, params)

  const getGoodsDetail = (params = {}) => vm.$u.get(GOODS_DETAIL_URL, params)
  const token = uni.getStorageSync('token') || ''
  vm.$u.api = {
    getSwiperdata,
    getCatitems,
    getFloordata,
    getCategories,
    getGoods,
    getGoodsDetail,
    // 🧨 注意：这里是 POST 请求
    getUserToken: (params = {}) => vm.$u.post(USERS_WXLOGIN, params),
    createOrder: (params = {}) =>
      vm.$u.post(MY_ORDERS_CREATE, params, {
        Authorization: token,
      }),
    orderPayParams: (params = {}) =>
      vm.$u.post(MY_ORDERS_REQ_UNIFIEDORDER, params, {
        Authorization: token,
      }),
    orderCheck: (params = {}) =>
      vm.$u.post(MY_ORDERS_CHKORDER, params, {
        Authorization: token,
      }),
    getOrderList: (params = {}) =>
      // 这里是 GET 请求
      vm.$u.get(MY_ORDERS_ALL, params, {
        Authorization: token,
      }),
  }
}

export default {
  install,
}
